package com.ch5;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author woldier
 * @version 1.0
 * @description volatile 两阶段终止
 * @date 2023/5/10 15:26
 **/
@Slf4j(topic = "c.Thread")
public class Demo01 {

//    private volatile static boolean phase = true;
    private  static boolean phase = false;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{

            while(true){
                if(phase) {
                    log.debug("监控终止,处理后事");
                    return;
                }
                log.debug("监控中....");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    log.debug("sleep被打断");
                }
            }
        },"监控线程");
        t1.start();
        Thread.sleep(4000);


        phase = true;
    }


}
